package com.iot.comprehensive.face.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PatternUtils {
    /***
     * 手机号码的校验
     * @param mobile 手机号码
     * @return 合法/非法
     */
    public static boolean isMobile(String mobile) {
        String regex = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3])|(17[5-8])|(18[0-9])|166|198|199|(147))\\d{8}$";
        Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
        Matcher m = p.matcher(mobile);
        return m.matches();
    }

    /***
     * 密码校验
     * @param password 密码
     * @return 合法/非法
     */
    public static boolean isPassword(String password) {
        String regex = "^.{6,18}$";
        Pattern p = Pattern.compile ( regex, Pattern.CASE_INSENSITIVE );
        Matcher m = p.matcher ( password );
        return m.matches ();
    }

    public static String GetTime(){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return df.format(new Date());
    }

    public static String getNumb(String str){
        str=str.trim();
        StringBuilder str2= new StringBuilder();
        if(!"".equals(str)){
            for(int i=0;i<str.length();i++){
                if(str.charAt(i)>=48 && str.charAt(i)<=57){
                    str2.append(str.charAt(i));
                }
            }

        }
        return str2.toString();
    }
}